﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TestWeb.Models.ViewModel>" %>

<script type="text/javascript">
    // Get list of selected items to be deleted
    checked = false;
    function checkedAll() {
        if (!checked)
            checked = true
        else
            checked = false

        var elems = document.getElementById('MySubmitForm').getElementsByTagName("input");

        for (var i = 0; i < elems.length; i++) {
            var type = elems[i].getAttribute("type");
            if (type == "checkbox")
                elems[i].checked = checked;
        }
    }

    // Checking whether any item was selected
    function checkInput() {
        var ids = "";
        var atLeastItemSelected = false;
        var elems = document.getElementById('MySubmitForm').getElementsByTagName("input");
        for (var i = 0; i < elems.length; i++) {
            var type = elems[i].getAttribute("type");
            if (type == "checkbox") {
                if (elems[i].checked) {
                    atLeastItemSelected = true;
                    ids += elems[i].value + ";";
                }
            }
        }
        // No any item was selected
        if (!atLeastItemSelected) {
            $(".red-left").text('At least a record must be selected for deleting');
            $("#message-red").fadeIn('fast').delay(<%= WebConfiguration.Instance.AlertTime %>).fadeOut('slow'); 
            return false;
        } else {
            document.getElementsByName("MaLoaiTinTucs").item(0).value = ids;
        }
        return true;
    }

    // Execute submit form
    function submitForm() {
        var errTxt = "";
        var confirmResult = confirm('Are you sure you want to Delete it? This action cannot be undone.');

        if (!confirmResult)
            return;

        // Checking whether any item was selected
        var checkResult = checkInput();

        if (checkResult) {
            $('#MySubmitForm').submit();
            return;
        }
    }
</script> 

<% using (Html.BeginForm("DeleteRangeOfLoaiTinTuc", "Admin", FormMethod.Post, new { id = "MySubmitForm" }))
   {%>
    <!-- start table-content  -->
    <div id="table-content">
        <!--  start message-red -->
        <div id="message-red">
	        <table border="0" width="100%" cellpadding="0" cellspacing="0">
		        <tr>
			        <td class="red-left">Error message</td>
		        </tr>
	        </table>
        </div>
        <!--  end message-red -->

        <!--  start message-blue -->
	    <div id="message-blue">
		    <table border="0" width="100%" cellpadding="0" cellspacing="0">
			    <tr>
				    <td class="blue-left">Information message</td>
			    </tr>
		    </table>
	    </div>
        <!--  end message-blue -->

        <script type="text/javascript">
        <% if (ViewData["Result"] != null)
           { 
                if(bool.Parse(ViewData["Result"].ToString()))
                {%>
                    $(".blue-left").text('<%= ViewData["MsgTxt"] %>');
                    $("#message-blue").fadeIn('fast').delay(<%= WebConfiguration.Instance.InfoTime %>).fadeOut('slow'); 
             <% }else
                { %>
                    $(".red-left").text('<%= ViewData["MsgTxt"] %>');
                    $("#message-red").fadeIn('fast').delay(<%= WebConfiguration.Instance.AlertTime %>).fadeOut('slow'); 
             <% } %>   
	    <% } %>
        </script>

	    <!-- start product-table -->
	    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
		    <tr>
                <th class="table-header-checkbox">
                    <a onclick="checkedAll();">Select All</a>/&nbsp;
                    <a onclick="submitForm();">Delete?</a>
                    <input type="hidden" name="MaLoaiTinTucs" />
                </th>
                <th class="table-header-check line-left">
				    <a href="#">ID</a>
			    </th>
			    <th class="table-header-repeat line-left">
				    <a href="#">TenLoaiTinTuc</a>
			    </th>
		    </tr>
	    <% for (int i = 0; i < Model.LoaiTinTucs.Count; i++)
	    {
		    var item = Model.LoaiTinTucs[i]; %>
		    <% if (i % 2 == 0)
		    { %>
		    <tr id="row-<%= item.ID %>" class="row-table odd-row">
		    <% }
		    else
		    { %>
		    <tr id="row-<%= item.ID %>" class="row-table even-row">
		    <% } %>
                <td align="center" style="padding-left: 0px;">
                    <input type="checkbox" value="<%= item.ID %>" />
                </td>
                <td>
				    <%= item.ID %>
			    </td>
			    <td>
				    <%= item.TenLoaiTinTuc %>
			    </td>
		    </tr>
	    <% } %>
	    </table>
	    <!-- end product-table -->
	    <!-- start paging -->
	    <div class="pagination">
	    <% 
		    var nextPage = (int)ViewData["CurrentPage"] + 1;
		    var totalPage = (int)ViewData["TotalPage"];
		    if (nextPage <= totalPage)
		    { %>
	    <%= Html.ActionLink(" ", "EnterDeleteRangeOfLoaiTinTuc", new { Page = nextPage })%>
		    <% } %>
	    </div>
	    <!-- end paging -->
    </div>
    <!-- end content-table  -->
<% } %>